import advListV from "../view/advList.ejs"
import advTableV from "../components/advTable.ejs";
import {getAdvList} from "../api/adv";
const advTypeEnum = {
	1:"轮播图广告",
	2:"轮播图底部广告",
	3:"热门回收广告",
	4:"优品精选广告"
}
const getAdvListAsync = async function(pageNo=1){
	const response = await getAdvList(pageNo,2);
	console.log(response);
	document.querySelector("#advTable").innerHTML = advTableV({
		...response,
		advTypeEnum
	});
	document.querySelector("#pageUl").onclick = function(e){
		const pageNo = e.target.dataset.page;
		if(pageNo){
			getAdvListAsync(pageNo/1)
		}
	}
}
export default ()=>{
	return  (req,res)=>{
		res.render(advListV());
		getAdvListAsync();
	}
}